package client;

import info.Message;

import java.io.IOException;

import users.Prof;

import common.ChatIF;

public class ProfessorClient extends AESSClient
{
	
	private String timeTable;
	private int maxcapacity;          //최대수용인원
	private int numberofRoom;         //강의실개수
	private int timeofTest;                //시험시간
	private String first;                       //1순위
	private String second;                //2순위
	private String third;                    //3순위
	private String forth;                    //4순위
	private String fifth;                    //5순위
	private String notPreferTime;    //희망하지 않는 시간
	private String taId;
	private String existTAreply;    //존재 하는지 여부 받은 답변 yes or no
	private String classTotalNum;
	private boolean classCurrentNum;
	private String []possibleDay=new String[6];
	private String []possibleTime=new String[6];
	private String []possibleRoom=new String[6];
	private String[][] selectTime=new String[6][1];
	
	
	public Prof user;
	public ProfessorClient(String host, int port, ChatIF clientUI)
			throws IOException {
		super(host, port, clientUI);
		// TODO Auto-generated constructor stub
	}

	
	public void setMaxCapacity(int a)
	{
		maxcapacity = a;
	}
	public void setNumberofRoom(int a)
	{
		numberofRoom = a;
	}
	public void setTimeofTest(int a)
	{
		timeofTest = a;
	}
	public void setPreferTime(String a,String b, String c, String d, String e)
	{
		first = a;
		second = b;
		third = c;
		forth = d;
		fifth = e;
	}
	public void setNotPreferTime(String a)
	{
		notPreferTime = a;
	}
	
	
	
	public void setTA(String taId)
	{
		this.taId = taId;
	}
	
	
	public String getTimeTable()
	{
		
		return timeTable;
	}
	
	public void setClassnot()
	{
		
		try {
			sendToServer("#classcheck"+":"+"NOT");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void sendMaxcapacity()
	{
		
		try {
			sendToServer("#maxcapacity"+":"+maxcapacity);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void sendNumberofRoom()
	{
		
		try {
			sendToServer("#numberofRoom"+":"+numberofRoom);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void sendTimeofTest()
	{
		
		try {
			sendToServer("#timeofTest"+":"+timeofTest);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void sendPreferTime()
	{
		
		try {
//			sendToServer("#prefertime"+":"+first+":"+second+":"+third+":"+forth+":"+fifth);
			Message msg = new Message();
			msg.msgHeader = "#examTime:" + user.course;
			String[] time =  {first,second,third,forth,fifth};
			msg.msgBody = time;
			
			sendToServer(msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void sendTA()
	{
		try {
			sendToServer("#registTA"+":"+taId);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void sendexistTA()
	{
		
		try {
			sendToServer("#inquiryTA"+":"+taId);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	
	public String getexistTA()
	{
		
		return existTAreply;
		
	}
	
	public void senddeleteTA()
	{
		
		try {
			sendToServer("#deleteTA"+":"+taId);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	
	public void requestTotalNum()
	{
		
		try {
			sendToServer("#requestTnum:" + user.course);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	
	public void requestCurrentNum()
	{
		
		try {
			sendToServer("#requestCnum:" + user.course);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	public String getTotalNum()
	{
		
		return classTotalNum;
		
	}
	
	public boolean getCurrentNum()
	{
		
		return classCurrentNum;
		
	}
	
	public void inquiryTime()
	{
		
		try {
			sendToServer("#inquiryTime");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void inquiryRoom()
	{
		
		try {
			sendToServer("#inquiryRoom");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void requireTimeTable()
	{
		
		try {
			sendToServer("#requireTimeTable");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public void sendSelectTime(Object object)
	{
		
		try {
			sendToServer("#sendSelectTime"+object);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void sendSelectRoom(Object object)
	{
		
		try {
			sendToServer("#sendSelectRoom"+object);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public String[] getPossibleTime()
	{
		
		return possibleTime;
		
	}
	
	public String[] getPossibleDay()
	{
		
		return possibleDay;
		
	}
	
	public String[] getPossibleRoom()
	{
		
		return possibleRoom;
		
	}
	   //서버로 부터 professor가 받아야 할 메세지 수정
 
 
 
	public void handleMessageFromServer(Object msg) 
	{
		  Message newMsg = (Message)msg;
		  
		  
		  String response = newMsg.msgHeader;
		  
		  System.out.println(response);
		  
		  if(response.contains("#시간표정보")){
			  timeTable = response.split(":")[1];
			  System.out.println("timeTable:" + timeTable);
			  
			
		  }
		  
		  if(response.contains("#totalStuNum")){
			  classTotalNum = response.split(":")[1];
			  System.out.println("classTotalNum:" + classTotalNum);
			  
			
		  }
		  
		  if(response.contains("#현재입력인원")){
			  classCurrentNum = Boolean.parseBoolean(response.split(":")[1]);
			  System.out.println("classCurrentNum:" + classCurrentNum);
			  
			
		  }
		  
		  if(response.contains("#checkStuNum")){
			  classCurrentNum = Boolean.parseBoolean(response.split(":")[1]);
			  System.out.println("classCurrentNum:" + classCurrentNum);
		  }
		  
		  if(response.contains("#TA등록여부")){
			  existTAreply = response.split(":")[1];
			  System.out.println("existTAreply:" + existTAreply);
			  
			
		  }
		  
		  if(response.contains("#possibleTimeList")){      //#최종시간리스트:몇일:시간
			  String[] res = new String[13];
			  
			  res = response.split(":");
			  possibleDay[0] = res[1];
			  possibleTime[0] = res[2];
			  possibleDay[1] = res[3];
			  possibleTime[1] = res[4];
			  possibleDay[2] = res[5];
			  possibleTime[2] = res[6];
			  possibleDay[3] = res[7];
			  possibleTime[3] = res[8];
			  possibleDay[4] = res[9];
			  possibleTime[4] = res[10];
			  possibleDay[5] = res[11];
			  possibleTime[5] = res[12];
			  
			  System.out.println(res[1] + "," + res[2]);
			  System.out.println("possibleTime:" + possibleTime);
			  
			
		  }
		  
		  if(response.contains("#possibleRoomList")){
			  String[] res = new String[13];
			  
			  res = response.split(":");
			  possibleRoom[0] = res[1];
			  possibleRoom[1] = res[2];
			  possibleRoom[2] = res[3];
			  possibleRoom[3] = res[4];
			  possibleRoom[4] = res[5];
			  possibleRoom[5] = res[6];
			  System.out.println("possibleRoom:" + possibleRoom);
			  
			
		  }
		  
		  
	
	}
	  
}
